﻿using Core.Domain;
using Core.DomainServices;
using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.DomainServices
{
    public class PatientParser : IHeaderParser<HtmlNodeCollection>
    {
        public Patient Parser(HtmlNodeCollection tables)
        {
            Patient item = new Patient();
            try
            {
                var patient = tables[0].SelectSingleNode("//name");
                item.FirstName = patient.SelectSingleNode("given").InnerText;
                item.LastName = patient.SelectSingleNode("family").InnerText;
                item.Gender = tables[0].ChildNodes[3].Attributes["code"].Value;


                item.DOB = tables[0].ChildNodes[5].Attributes["value"].Value.Substring(0, 8);
            }
            catch { }
            return item;
        }
    }
}
